package com.yangjun.common.timetask;

import java.io.IOException;
import java.util.List;

import org.codehaus.jackson.JsonGenerationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.yangjun.dao.mybatis2.mapper.waresAnalyse.WaresAnalyseMapper;
import com.yangjun.utils.JSONUtils;
import com.yangjun.utils.RedisClientLocalUtils;


@Component
public class ScheduledWaresAnalyseTask {
	
	@Autowired
	public WaresAnalyseMapper mapper;
	private static RedisClientLocalUtils rc = new RedisClientLocalUtils();
	
	@Scheduled(cron = "0 */30 * * * *")
	public void getSearchContent() {
		System.err.println("****************ScheduledWaresAnalyseTask**************");
		String[]  contents = {"waregeneralname","brandname","manufacturername","warename"};
		try {
		for (String content : contents) {
			List<String> contentList = mapper.getSearchContent(content);
			rc.setKeyValue(content, JSONUtils.objToStr(contentList));
		}
		List<String> suppliernameList = mapper.getSearchContentSuppliername();
		rc.setKeyValue("suppliername", JSONUtils.objToStr(suppliernameList));
		} catch (JsonGenerationException e) {
			e.printStackTrace();
		} catch (JsonMappingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
